/**
 * Project Name:YCApiServer-common
 * File Name:IpAddress.java
 * Package Name:com.qiniu.util
 * Date:2016年7月11日下午3:40:19
 * Copyright (c) 2016 
 *
 */
package com.qiniu.util;

import javax.servlet.http.HttpServletRequest;

/**
 * ClassName: IpAddress <br/>
 * Function: 获取IP地址. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2016年7月11日 下午3:40:19 <br/>
 *
 * @author qinhaiguan
 * @version
 */
public class IpUtil {
	
	public static String getIpAddr(HttpServletRequest request) { 
	    String ip = request.getHeader("x-forwarded-for"); 
	    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
	        ip = request.getHeader("PRoxy-Client-IP"); 
	    } 
	    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
	        ip = request.getHeader("WL-Proxy-Client-IP"); 
	    } 
	    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
	        ip = request.getRemoteAddr(); 
	    } 
	    return ip; 
	}  

}
